import { mergeState } from "../util/functions";
import { getUserInfo } from "../api/users";

export default {
    namespaced: true,
    state: {
        user: {},
        loaded: {}
    },
    mutations: {
        mergeState
    },
    actions: {
        async getUserInfo({ commit, state }, force = false) {
            const { basic } = state.user;
            if (force || !basic) {
                const res = await getUserInfo();
                commit("mergeState", {
                    user: { basic: res.data },
                    loaded: { basic: true }
                });
            }
        }
    }
};
